package com.freewater.library.catalogue.presentation.request;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.freewater.library.catalogue.application.command.CreateBookCommand;
import io.swagger.v3.oas.annotations.Parameter;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDate;

@Data
public class CreateBookRequest {

    @Parameter(description = "ISBN")
    @NotBlank(message = "ISBN不能为空")
    private final String isbn;

    @Parameter(description = "标题")
    @NotBlank(message = "标题不能为空")
    private final String title;

    @Parameter(description = "副标题")
    private final String subtitle;

    @Parameter(description = "作者")
    private final String author;

    @Parameter(description = "出版社")
    private final String publishingHouse;

    @Parameter(description = "出版日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private final LocalDate publicationDate;

    @Parameter(description = "封面图")
    private final String cover;

    @Parameter(description = "定价")
    private final BigDecimal listPrice;

    @Parameter(description = "页数")
    private final Integer pageCount;

    @Parameter(description = "装帧")
    private final String bindingAndLayout;

    @Parameter(description = "丛书")
    private final String series;

    @Parameter(description = "介绍/描述")
    private final String description;

    public CreateBookCommand toCommand() {
        return new CreateBookCommand(
                this.getIsbn(),
                this.getTitle(),
                this.getSubtitle(),
                this.getAuthor(),
                this.getPublishingHouse(),
                this.getPublicationDate(),
                this.getCover(),
                this.getListPrice(),
                this.getPageCount(),
                this.getBindingAndLayout(),
                this.getSeries(),
                this.getDescription()
        );
    }
}
